import requests
from flask import current_app


class Httper:
    isbn_url = 'https://api.douban.com/v2/book/isbn/{}'
    word_url = 'https://api.douban.com/v2/book/search?q={}&start={}&count={}'

    @classmethod
    def get_isbn_book(cls,isbn):
        url=cls.isbn_url.format(isbn)
        result = requests.get(url)
        return result.json()


    @classmethod
    def get_word_book(cls,word,page,count=current_app.config['PER_PAGE']):
        url=cls.word_url.format(word,cls.get_page_start(page),count)
        result = requests.get(url)
        return result.json()

    @classmethod
    def get_page_start(cls,page):
        return (page-1)*current_app.config['PER_PAGE']



if __name__ == '__main__':
    Httper.get_isbn_book(9787806737842)
    Httper.get_word_book('无敌')